<?php 
	require_once 'SQLHelper.class.php';
	class MessageService{
		//添加信息到数据库中
		public function addMessage($sender, $getter, $con){
			$sqlhelper = new SQLHelper();
			$sql = "insert into messages (sender,getter,content,sendTime,isGet) values('$sender','$getter','$con',now(), 0)";
			file_put_contents("d:/mylog.log",$sql."\r\n",FILE_APPEND);
			return $sqlhelper->exc_dml($sql);			
		}
		
		public function getMessage($sender, $getter){
			$sqlHelper = new SQLHelper();
			$sql = "select * from messages where getter='$getter' and sender='$sender' and isGet = 0";
			$arr = $sqlHelper->exc_dql2($sql);
			//返回，现在定义返回客户端消息格式
			//$mesesInfo="<meses><mes><id></id><sender></sender><getter></getter><con></con><sendTime></sendTime></mes></meses>";
			$mesesInfo = "<meses>";
			foreach($arr as $row){
				$mesesInfo.="<mes><id>{$row['id']}</id><sender>{$row['sender']}</sender><getter>{$row['getter']}</getter><con>{$row['content']}</con><sendTime>{$row['sendTime']}</sendTime></mes>";
			}
			$mesesInfo.="</meses>";
			
			$sql = "update messages set isGet=1 where getter='$getter' and sender='$sender'";
			$sqlHelper->exc_dml($sql);
			//file_put_contents("d:/mylog.log",$mesesInfo.date()."|".$sender."|"."\r\n",FILE_APPEND);
			$sqlHelper->connect_close();
			
			return $mesesInfo;
		}
	}
?>